import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    message: "这是一个全局组件",
    data: { name: "张三", age: 14 },
  },
  //mutations 只能修改同步的数据
  mutations: {
    changeMessage(state, payload) {
      console.log(store);
      state.message = payload;
    },
    changeData(state, payload) {
      state.data = payload;
    },
  },
  actions: {
    changeMessageAsync(ctx, payload) {
      ctx.commit("changeMessage", payload);
    },
  },
});

export default store;
